package com.example.park2212.points

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager

import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.TimeUtils
import com.example.lib_base.entity.DateBean
import com.example.lib_base.mvvm.BaseActivity
import com.example.park2212.R
import com.example.park2212.databinding.ActivityPointPatrolBinding
import dagger.hilt.android.AndroidEntryPoint
import java.util.Calendar

@AndroidEntryPoint
@Route(path = "/app/points/PointPatrolActivity")
class PointPatrolActivity : BaseActivity<ActivityPointPatrolBinding,PointsViewModel>() {
    lateinit var dateAdapter:DateAdapter
    lateinit var ppAdapter: PpAdapter

    override fun initView() {
        var calendar = Calendar.getInstance()
        val week = calendar.get(Calendar.DAY_OF_WEEK)


        val list = mutableListOf<DateBean>()
        for (i in -(week - 1) .. -(week - 1)+6){
            calendar = Calendar.getInstance()
            calendar.add(Calendar.DAY_OF_MONTH, i)
            val day = calendar.get(Calendar.DAY_OF_MONTH)
            val week1 = TimeUtils.getChineseWeek(calendar.time).substring(1,2)
            list.add(DateBean(week1,day,if (i == 0) true else false))
        }


        dateAdapter = DateAdapter()
        dateAdapter.addData(list)
        binding.taskRvdate.adapter = dateAdapter
        binding.taskRvdate.layoutManager = GridLayoutManager(this,7)


        ppAdapter = PpAdapter()
        binding.taskRv.adapter = ppAdapter
        binding.taskRv.layoutManager = LinearLayoutManager(this)
        viewModel.order("2")

        ppAdapter.setOnItemClickListener { adapter, view, position ->
            ARouter.getInstance().build("/app/points/TaskDetailActivity")
                .withString("tid",ppAdapter.data[position].id.toString()).navigation()
        }

    }

    override fun initData() {
        viewModel.orderSuccess.observe(this){
            ppAdapter.data.clear()
            ppAdapter.addData(it)
            ppAdapter.notifyDataSetChanged()
        }
    }



}